<#include "/basicdata/common/scripts.html">

<style type="text/css">
    /***隐藏导出按钮**/
    .dt-buttons {
        display: none;
    }
</style>
<body>
<div class="fh-model" style="height:400px;">
    <div class="oper-search">
        <form class="form-inline" id="searchForm">
            <input type="hidden" id="postGroupId" value="${postGroupId}" >
            <input type="hidden" id="companyCode" value="${companyCode}"/>
            <div class="form-group">
                <label>用户姓名</label>
                <input id="name" name="name" type="text" class="form-control"/>
            </div>
            <div class="form-group">
                <label>登录名</label>
                <input id="username" name="username" type="text" class="form-control"/>
            </div>
            <div class="form-group">
                <span class="btn glyphicon glyphicon-search btn-sm" onclick="searchUserBtn()">查询</span>
            </div>
            <input type="text" id="delFlag" name="delFlag" value="0" hidden>
        </form>
    </div>
    <div class="tableClass">
        <table id="userTable" class="eamtable">
        </table>
    </div>
</div>
<div class="div-model-btn">
    <div class="model-btn" id="btn_confirm" onclick="sub()">确定</div>
</div>
</body>
<script>
    var userTable = $("#userTable");
    $(function() {
        sys.useSimpleRetrieveData();
        var staticPrefix = "${static}";
        var config = sys.DynamicDatabeConfig(staticPrefix,getSearchUrl(),[
            {
                data:null,
                width:15,
                title:"<div class='pretty success' style='margin: 0;'>"+
                    "<input type='checkbox' class='checker check-all' >"+
                    "<label><i class='mdi mdi-check'></i></label></div>",
                render: function(data){
                    return  '<div class="pretty success" style="margin: 0;">'+
                        '<input type="checkbox" class="checker check-item"  data-id="'+data.id+'">'+
                        '<label><i class="mdi mdi-check"></i></label>'+
                        '</div>';
                }
            },
            {
                data : null,
                width:20,
                title:'序号',
                render : function(data, type, full, meta){
                    return meta.row + 1 + meta.settings._iDisplayStart;
                }
            },
            {
                data : 'username',
                title:'登录名'
            },
            {
                data : 'name',
                title:'姓名',

            },
            {
                data : 'userCode',
                title:'工号'
            },
        ],true, {ordering:true});
        config.bSort=false;
        config.aLengthMenu = [10,25,50,100];
        config.scrollX = true;
        config.autoWidth=true;
        config.scrollY = '65%';
        config.createdRow=null;//与main.js选中行冲突，此页面去除
        userTable.dataTable(config);
        userTable.DataTable().on('draw', function() {
            checkGroup.autoSetSelect();
        });
    })

    function getSearchParam() {
        var companyCode = $("#companyCode").val().trim();
        var username = $("#username").val().trim();
        var name = $("#name").val().trim();
        var delFlag = $("#delFlag").val().trim();
        var param = 'companyCode='+companyCode+'&username='+username+'&name='+name+"&delFlag="+delFlag;
        return param;
    }

    function getSearchUrl(){
        var url = '${ctx}/user/ajaxPageInfo?' + getSearchParam();
        url = encodeURI(url);
        return url;
    }

    function searchUserBtn() {
        userTable.DataTable().ajax.url(getSearchUrl()).load(null, false);
    }

    var checkGroup = new iUtils.CheckGroup({
        table:userTable,
        callback:function(table,ele,arr){
            var data = table.fnGetData($(ele).parents("tr")[0]);
            var id = data.id;
            data.id = "";
            arr[id] = data;
        }
    });

    function sub(){
        var arr = checkGroup.getAllCheckedIds();
        if(isEmpty(arr)){
            sys.topmsg("至少勾选一项之后再操作！");
            return
        }
        //点击确定，将选中行保存
        $.ajax({
            url : "${ctx}/postGroup/saveUserPost",
            type : "POST",
            datatype : "json",
            data :
                {
                    "postGroupId" : $("#postGroupId").val(),
                    "userIds" : arr.join(","),
                },
            success : function(data) {
                if (data.success) {
                    js.showMessage(data.data,"","success",1500);
                    parent.reload();
                    sys.frameDialogClose();
                } else {
                    sys.topmsg("添加用户失败！");
                }
            },
            error : function(data) {
                js.showMessage("请求异常！","","error",1500)
            }
        });
    }
</script>